<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目进度调度任务列表')" />
    <style>
        .badge-success{
            background-color: #1ab394;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>进度名称：</p>
                                <input type="text" name="processName"/>
                            </li>
                            <li class="select-time">
                                <p>有效日期：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginStartDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endStartDate]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="linkong:process:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="linkong:process:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="linkong:process:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('linkong:process:edit')}]];
        var removeFlag = [[${@permission.hasPermi('linkong:process:remove')}]];
        var prefix = ctx + "linkong/process";
        var datas = [{dictLabel:'启用',dictValue:'0',listClass:"success"},{dictLabel:'未启用',dictValue:'1',listClass:"info"}]
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "调度任务",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'processId', 
                    title : '进度主键',
                    visible: false
                },
                {
                    field : 'processName',
                    align: 'center',
                    title : '进度名称'
                },

                {
                    field : 'reportingCycle',
                    align: 'center',
                    title : '上报周期',
                    formatter:function (value) {
                        if(value=='0'){
                            return '临时';
                        }
                        if(value=='1'){
                            return '月报';
                        }
                        if(value=='2'){
                            return '季报';
                        }
                    }
                },
                {
                    field : 'startDate',
                    align: 'center',
                    title : '有效开始日期'
                },
                {
                    field : 'endDate',
                    align: 'center',
                    title : '有效截至日期'
                },
                {
                    field : 'status',
                    align: 'center',
                    title : '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field : 'remark',
                    align: 'center',
                    title : '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status == '1'){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="enable(\'' + row.processId + '\')"><i class="fa fa-edit"></i>启用</a> ');
                        }else if(row.status == '0'){
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="disable(\'' + row.processId + '\')"><i class="fa fa-edit"></i>禁用</a> ');
                        }
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.processId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        /* 禁用 */
        function disable(processId) {
            $.modal.confirm("确认要禁用吗？", function() {
                $.operate.post(prefix + "/enableOrNotProcess", { "processId": processId, "status": 1 });
            })
        }

        /* 启用 */
        function enable(processId) {
            $.modal.confirm("确认要启用吗？", function() {
                $.operate.post(prefix + "/enableOrNotProcess", { "processId": processId, "status": 0 });
            })
        }
    </script>
</body>
</html>